package com.ruoyi.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.CategoryOne;
import com.ruoyi.service.ICategoryOneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/webshop/categoryOne")
public class CategoryOneController extends BaseController {

    @Autowired
    private ICategoryOneService categoryOneService;

    /**
     * 查所有
     */
    @GetMapping("/list")
    public AjaxResult selectAll() {
        List<CategoryOne> list = categoryOneService.selectAll();
        return AjaxResult.success(list);
    }
    /**
     * 查所有
     */
    @GetMapping("/listCascater")
    public AjaxResult selectListCascater() {
        List<Map<String, Object>> list = categoryOneService.selectListCascater();
        return AjaxResult.success(list);
    }

    /**
     * 根据id 查一条
     */
    @GetMapping("/{id}")
    public CategoryOne selectById(@PathVariable() Long id) {
        return categoryOneService.selectById(id);
    }

    /**
     * 查分页
     */
    @GetMapping("/page")
    public TableDataInfo selectPage(CategoryOne categoryOne) {
        startPage();

        List<CategoryOne> list = categoryOneService.selectPage(categoryOne);

        return getDataTable(list);
    }
    /**
     * 添加
     */
    @PostMapping()
    public int insertOne(@RequestBody CategoryOne categoryOne) {
        return categoryOneService.insertOne(categoryOne);
    }

    /**
     * 修改
     */
    @PutMapping()
    public int updateById(@RequestBody CategoryOne categoryOne) {
        return categoryOneService.updateById(categoryOne);
    }

    /**
     * 删除
     */
    @DeleteMapping("/{ids}")
    public int deleteByIds(@PathVariable() Long[] ids) {
        return categoryOneService.deleteByIds(ids);
    }
}